﻿//------------------------------------------------------------------------------------------------- 
// <copyright file="EnvironmentHelper.cs" company="Collaboris">
// Copyright (c) Collaboris.  All rights reserved.
// </copyright>
// <summary>Defines the Environment Helper type.</summary>
//-------------------------------------------------------------------------------------------------

namespace Collaboris.Utils
{
    using System;
    using System.IO;
    using System.Security.Principal;

    public class EnvironmentHelper
    {
        public static string GetCurrentMachineName()
        {
            string machineName = System.Environment.MachineName;
            return machineName;
        }

        public static string GetCurrentDirectory()
        {
            //get the full location of the assembly with DaoTests in it 
            string fullPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

            //get the folder that's in 
            string directoryName = Path.GetDirectoryName(fullPath);

            return directoryName;

        }

        /// <summary>
        /// Gets the user account.
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentUserAccount()
        {
            WindowsIdentity identity = WindowsIdentity.GetCurrent();
            string user = null;

            if (identity != null)
            {
                user = identity.Name;
            }

            if (string.IsNullOrEmpty(user))
            {
                user = GetCurrentMachineName() + @"\" + Environment.UserName;
            }

            return user;
        }
    }
}
